#ifndef GAUGE_H
#define GAUGE_H

#include <QObject>
#include <QWidget>
#include <QPainter>

class Gauge : public QWidget
{
    Q_OBJECT
public:
    enum ScalePosition {
        INSIDE = 0,
        OUTSIDE,
        ON,
        OUTSIDE_GAP,
    };
    enum PointerStyle {
        SHARP = 0,
        CIRCLE,
    };

    explicit Gauge(QWidget *parent = nullptr);
    int getStartAngle() { return _startAngle; }
    void setStartAngle(int startAngle);
    int getSpanAngle() { return _spanAngle; }
    void setSpanAngle(int spanAngle);
    int getRingWidth() { return _ringWidth; }
    void setRingWidth(int ringWidth);
    QColor getRingColor() { return _ringColor; }
    void setRingColor(QColor color);
    Qt::PenCapStyle getPenCapStyle() { return _ringStyle; }
    void setPenCapStyle(Qt::PenCapStyle ringStyle);
    int getMinorScale() { return _minorScale; }
    void setMinorScale(int minorScale);
    int getMajorScale() { return _majorScale; }
    void setMajorScale(int majorScale);
    QColor getScaleColor() { return _scaleColor; }
    void setScaleColor(QColor scaleColor);
    int getScalePosition() { return _scalePosition; }
    void setScalePosition(ScalePosition scalePosition);
    float getMinValue() { return _minValue; }
    void setMinValue(float minValue);
    int getMaxValue() { return _maxValue; }
    void setMaxValue(float maxValue);
    float getTargetValue() { return _targetValue; }
    void setTargetValue(float targetValue);
    int getPrecision() { return _precision; }
    void setPrecision(int precision);
    QColor getScaleValueColor() { return _scaleValueColor; }
    void setScaleValueColor(QColor color);
    PointerStyle getPointerStyle() { return _pointerStyle; }
    void setPointerStyle(PointerStyle pointerStyle);
    QColor getPointerColor() { return _pointerColor; }
    void setPointerColor(QColor color);
    bool getCurrentRing() { return _currentRing; }
    void setCurrentRing(bool flag);
    QColor getCurrentRingColor() { return _currentRingColor; }
    void setCurrentRingColor(QColor color);
    QString getTitle() { return _title; }
    void setTitle(const QString& title);
    QString getUnit() { return _unit; }
    void setUnit(const QString& unit);
    QColor getTitleColor() { return _titleColor; }
    void setTitleColor(QColor color);
protected:
    void paintEvent(QPaintEvent* event) override;
private:
    void drawRing(QPainter& painter, int startAngle, int spanAngle, QColor color);
    void drawScale(QPainter& painter);
    void drawScaleValue(QPainter& painter);
    void drawPointer(QPainter& painter);
    void drawTitle(QPainter& painter);
    int _startAngle { 225 };
    int _spanAngle { 270 };
    int _ringWidth { 10 };
    QColor _ringColor = QColor(231, 235, 249);
    Qt::PenCapStyle _ringStyle = Qt::SquareCap;
    int _minorScale { 10 };
    int _majorScale { 5 };
    QColor _scaleColor = QColor(100, 103, 123);
    ScalePosition _scalePosition { ScalePosition::INSIDE };
    float _minValue { 0 };
    float _maxValue { 100 };
    float _targetValue { 50 };
    int _precision { 0 };
    QColor _scaleValueColor = QColor(100, 103, 123);
    PointerStyle _pointerStyle = PointerStyle::SHARP;
    QColor _pointerColor = QColor(230, 100, 100);
    bool _currentRing { false };
    QColor _currentRingColor = QColor(230, 100, 100);
    QString _unit;
    QString _title;
    QColor _titleColor = QColor(70, 70, 70);
signals:
};

#endif // GAUGE_H
